package org.red_cross_service.controller;

import jakarta.servlet.http.HttpServletResponse;
import org.red_cross_service.domain.entity.ActivityEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.red_cross_service.common.anno.NoNeedToken;
import org.red_cross_service.common.response.Response;
import org.red_cross_service.service.ServiceComponent;


@RestController
@RequestMapping("/api/activity")
@CrossOrigin
public class ActivityController {

    @Autowired
    ServiceComponent serviceComponent;
    //获取所有活动
    @NoNeedToken
    @GetMapping("/getList")
    public Response getAllActivity(@RequestParam Integer type,@RequestParam Integer userId) {
        if(type == null) return Response.error("参数为空");
        return serviceComponent.getActivityService().getAllActivity(type,userId);
    }

    //依据id查询用户活动详情
    @GetMapping("/selectOne")
    @NoNeedToken
    public Response selectOne(@RequestParam Integer activityId,@RequestParam Integer userId) {
        return serviceComponent.getActivityService().getActivityOne(activityId,userId);
    }

    @NoNeedToken
    @PostMapping("/list")
    public Response getActivityList(@RequestBody ActivityEntity activityEntity) {
        return serviceComponent.getActivityService().getActivityList(activityEntity);
    }
    //新增活动
    @NoNeedToken
    @PostMapping("/add")
    public Response addActivity(@RequestBody ActivityEntity activityEntity) {
        return serviceComponent.getActivityService().add(activityEntity);
    }

    //修改活动
    @NoNeedToken
    @PostMapping("/update")
    public Response updateActivity(@RequestBody ActivityEntity activityEntity) {
        return serviceComponent.getActivityService().update(activityEntity);
    }
    //删除活动
    @NoNeedToken
    @DeleteMapping("/delete")
    public Response deleteActivity(@RequestParam Integer activityId) {
        return serviceComponent.getActivityService().delete(activityId);
    }

    //查询单挑记录
    @NoNeedToken
    @PostMapping("/selectOne")
    public Response selectOne(@RequestBody ActivityEntity activityEntity) {
        return serviceComponent.getActivityService().selectOne(activityEntity);
    }

    @NoNeedToken
    @PostMapping("/export")
    public void exportActivity(HttpServletResponse response, @RequestBody ActivityEntity activityEntity){
        serviceComponent.getActivityService().exportActivity(response,activityEntity);
    }




}
